package gitee.derumin.lifeissohard.client;

import gitee.derumin.lifeissohard.item.LishItems;
import gitee.derumin.lifeissohard.tools.LishIdentifiers;
import gitee.derumin.lifeissohard.tools.LishNetworkPackets;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.item.ModelPredicateProviderRegistry;


@Environment(EnvType.CLIENT)
public class LifeissohardClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        ModelPredicateProviderRegistry.register(LishItems.BLOOD_TESTER,LishIdentifiers.Items.ModelPredicates.BLOOD_TESTER_TESTING,(itemStack, clientWorld, livingEntity, i) -> {
            if(livingEntity == null){
                return 0.0f;
            }
            return livingEntity.isUsingItem() && livingEntity.getActiveItem() == itemStack ? 1.0f : 0.0f;
        });
        ModelPredicateProviderRegistry.register(LishItems.BLOOD_TESTER,LishIdentifiers.Items.ModelPredicates.BLOOD_TESTER_TEST_STEP, (itemStack, clientWorld, livingEntity,i) -> {
            if (livingEntity == null) {
                return 0.0F;
            }
            return livingEntity.getActiveItem() != itemStack ? 0.0F : (itemStack.getMaxUseTime() - livingEntity.getItemUseTimeLeft()) / 100.0F;
        });
        ClientPlayNetworking.registerGlobalReceiver(LishIdentifiers.Packets.S2CPackets.HUNGER_MANAGER_PACKET,((client, handler, buf, responseSender) -> LishNetworkPackets.applyHungerManagerPacket(client,buf)));
    }
}
